#pragma once

#include "Common.h"
#include "Vector3.h"
#include "IndexBuffer.h"
#include "VertexBuffer.h"
#include "TextureManager.h"

struct AdtHeader
{
	unsigned int Flags;
	unsigned int McinOffset;
	unsigned int MtexOffset;
	unsigned int MmdxOffset;
	unsigned int MmidOffset;
	unsigned int MwmoOffset;
	unsigned int MwidOffset;
	unsigned int MddfOffset;
	unsigned int ModfOffset;
	unsigned int MfboOffset;
	unsigned int Mh20Offset;
	unsigned int MtfxOffset;
	unsigned int Padding[4];
};

struct AdtMcin
{
	unsigned int McnkOffset;
	unsigned int Size;
	unsigned int Flags;
	unsigned int AsyncID;
};

struct AdtMtex
{
};

struct AdtMcnk
{
	char			Magic[4];
	unsigned int	Flags;
	unsigned int	IndexX;
	unsigned int	IndexY;
	unsigned int	LayerCount;
	unsigned int	DoodadReferenceCount;
	unsigned int	McvtOffset;
	unsigned int	McnrOffset;
	unsigned int	MclyOffset;
	unsigned int	McrfOffset;
	unsigned int	McalOffset;
	unsigned int	AlphaSize; 
	unsigned int	McshOffset;
	unsigned int	ShadowSize;
	unsigned int	AreaID;
	unsigned int	MapObjectReferenceCount;
	unsigned int	Holes;
	unsigned int	LowQualityTextureMap[4];
	unsigned int	PredTex;	//Unknown
	unsigned int	DoodadNoEffect;
	unsigned int	McseOffset;
	unsigned int	SoundEmitterCount;
	unsigned int	MclqOffset;
	unsigned int	LiquidSize;
	unsigned int	MccvOffset;
	Vector3f		Position;
	unsigned int	Pad0;
	unsigned int	Pad1;
};

struct AdtMcvt
{
	float Heights[145];
};

struct AdtMcnr
{
	Vector3i Normals[435];
};

class Adt
{
public:
	Adt();
public:
	~Adt();
public:
	void Load(char* path);
	void Draw() const;
private:
	void CreateVertexBuffer();
	void CreateIndexBuffer();
private:
	AdtHeader		m_oHeader;
	AdtMcnk			m_pChunks[256];
	AdtMcin			m_pChunkInformations[256];
	float			m_pHeights[256][145];
	IndexBuffer*	m_pIndexBuffer;
	VertexBuffer*	m_pVertexBuffer;
};